package westh.ilib.util;

import java.util.List;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import westh.ilib.util.Constant;


/**
 * 
 * author:  @author yanfei
 * date  :  Aug 10, 2010
 * 
 */

public class PageInfo {

    private int pageNO;
    private int pageSize;
    private int maxCount;
    private List pageList;
    private Object otherObj;

    public PageInfo() {
        pageNO = 0;
        pageSize = 0;
        maxCount = 0;
        pageList = new ArrayList();
    }
    
    public int getPageNO() {
        return pageNO;
    }
    
    public void setPageNO(int pageNO) {
        this.pageNO = pageNO;
    }
    
    public int getPageSize() {
        return pageSize;
    }
    
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    
    public int getMaxCount() {
        return maxCount;
    }
    
    public void setMaxCount(int maxCount) {
        this.maxCount = maxCount;
    }
    public java.util.List getPageList() {
        return pageList;
    }
    
    public void setPageList(java.util.List pageList) {
        this.pageList = pageList;
    }
    
    public Object getOtherObj() {
        return otherObj;
    }

    public void setOtherObj(Object otherObj) {
        this.otherObj = otherObj;
    }
    
    public int getPageCount() {
        int iPageCount = 0;
        if( this.pageSize!=0 ){
            if( ( this.maxCount % this.pageSize ) == 0 ){
                iPageCount = this.maxCount / this.pageSize;
                return iPageCount;
            }
            else{
                iPageCount = maxCount/pageSize;
                return iPageCount + 1;
            }
        }
        else{
            return maxCount;
        }
    }
    
    public int getPageSizeFromJSP( String strPageSize ){
        int iPageSize = 0;
        //String strPageSize = null;

        //strPageSize = (String)request.getParameter("pageSize");
        if( strPageSize==null || strPageSize.equals("")|| strPageSize.equals("0") ){
            iPageSize = Constant.getConPagesize(); ////////////////////////////////////
        }
        else{
            try {
                iPageSize = Integer.parseInt( strPageSize );
            }
            catch (Exception ex) {
                iPageSize = Constant.getConPagesize(); ////////////////////////////////////
                System.out.println( "Developer Debug Log: [ pageSize parameter is incorrect! ]" );
            }
        }
        return iPageSize;
    }

    //
    public int getPageSizeFromJSP( HttpServletRequest request ){
        int iPageSize = 0;
        String strPageSize = null;

        strPageSize = (String)request.getParameter("pageSize");
        if( strPageSize==null || strPageSize.equals("") ){
            iPageSize = Constant.getConPagesize(); ////////////////////////////////////
        }
        else{
            try {
                iPageSize = Integer.parseInt( strPageSize );
            }
            catch (Exception ex) {
                iPageSize = Constant.getConPagesize(); ////////////////////////////////////
                System.out.println( "Developer Debug Log: [ pageSize parameter is incorrect! ]" );
            }
        }
        return iPageSize;
    }
    
    public int getPageNoFromJSP( String strPageNo ){
        int iPageNo = 0;
        //String strPageNo = null;

        //strPageNo = (String)request.getParameter("pageNo");
        if( strPageNo==null || strPageNo.equals("")|| strPageNo.equals("0") ){
            iPageNo = 1; ////////////////////////////////////
        }
        else{
            try {
                iPageNo = Integer.parseInt( strPageNo );
            }
            catch (Exception ex) {
                iPageNo = 1; ////////////////////////////////////
                System.out.println( "Developer Debug Log: [ pageNo parameter is incorrect! ]" );
            }
        }
        return iPageNo;
    }

    public int getPageNoFromJSP( HttpServletRequest request ){
        int iPageNo = 0;
        String strPageNo = null;

        strPageNo = (String)request.getParameter("pageNo");
        if( strPageNo==null || strPageNo.equals("") ){
            iPageNo = 1; ////////////////////////////////////
        }
        else{
            try {
                iPageNo = Integer.parseInt( strPageNo );
            }
            catch (Exception ex) {
                iPageNo = 1; ////////////////////////////////////
                System.out.println( "Developer Debug Log: [ pageNo parameter is incorrect! ]" );
            }
        }
        return iPageNo;
    }

}
